public class Solution1 {
    //将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
    public ListNode mergeTwoLists(ListNode headA,ListNode headB) {
        ListNode newH = new ListNode();
        ListNode tmpH = newH;
        while(headA != null && headB != null) {
            if(headA.val < headB.val) {
                tmpH.next = headA;
                tmpH = headA;
                headA = headA.next;
            }else {
                tmpH.next = headB;
                tmpH = headB;
                headB = headB.next;
            }
        }
        if(headA == null) {
            tmpH.next = headB;
        }if(headB == null) {
            tmpH.next = headA;
        }
        return newH.next;
    }
}
